package net.xdclass.strategy;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ShardingTableConfig {

    /**
     * 启用存储数据表位置编号
     */
    private static final List<String> tablePrefixList = new ArrayList<>();
    private static Random random = new Random();

    // 配置启用那些库的前缀
    static {
        tablePrefixList.add("0");
        tablePrefixList.add("a");
    }

    /**
     * 获取随机的前缀
     * @return
     */
    public static String getRandomTablePrefix(String code) {
//        int i = random.nextInt(tablePrefixList.size());
        int hashCode = code.hashCode();
        int i = Math.abs(hashCode) % tablePrefixList.size();
        return tablePrefixList.get(i);
    }

}
